package com.deschen.security.core.validate.code.sms;

import com.deschen.security.core.properties.SecurityConstants;
import com.deschen.security.core.validate.code.AbstractValidateCodeProcessor;
import com.deschen.security.core.validate.code.ValidateCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * @Author deschen
 * @Create 2019/8/23
 * @Description
 * @Since 1.0.0
 */
@Component
public class SmsValidateCodeProcessor extends AbstractValidateCodeProcessor<ValidateCode> {

    @Autowired
    private SmsValidateCodeSender smsValidateCodeSender;

    @Override
    protected void send(ServletWebRequest request, ValidateCode validateCode) throws Exception {
        smsValidateCodeSender.send(ServletRequestUtils.getStringParameter(request.getRequest(), SecurityConstants.DEFAULT_PARAMETER_NAME_MOBILE),
                validateCode.getCode());
    }
}
